<?php
class APIAuthenticationService extends AuthenticationService {
    public function authenticate() {
        // for test only
        $token = sfContext::getInstance()->getRequest()->getParameter('token') ;
        $customerLDAP = new CustomLDAP() ;
        $username = $customerLDAP->checkToken($token);
        if ($username == false) {
            ApiBaseClass::getInstance()->_data['errors'] = 1;
            ApiBaseClass::getInstance()->_data['message'] = 'Invalid token' ;
            return ;
        }
        // authenticate using token before the user can continue
        $query = Doctrine_Query::create() -> from('SystemUser') -> where('user_name = ?', $username) -> andWhere('deleted = 0');
        $user = $query -> fetchOne();
        if ($user instanceof SystemUser) {
            $this->setBasicUserAttributes($user);
            $this->setBasicUserAttributesToSession($user);
            $this->setRoleBasedUserAttributes($user);
            $this->setRoleBasedUserAttributesToSession($user);
            $this->setSystemBasedUserAttributes($user, $additionalData);
            $this->setSystemBasedUserAttributesToSession($user, $additionalData);

            $this->getCookieManager()->setCookie('Loggedin', 'True', 0, '/');
            return true ;
        }
        return false ;
    }

}
?>